#!/bin/sh

# Warning : be consistent with the order of REPS and
# the table header in the latex file !!!!

REPS="$HOME/SysPool/Systems"
MAPLE="maple13"
LOG="intlog"
TESTS="Triangularize" # RealTriangularize RRC
FICTESTS=$2

usage(){
    echo "Usage : $0 ListOfFiles "
    exit 1
}

error(){
    echo "Error : $* "
    exit 1
}

[ -e "$FICTESTS" ] || error "File of tests does not exist"

[ ! -e "$LOG" ] || error "Log File $LOG already exists, remove it first"

echo "$REPS" >> $LOG
for line in `cat $FICTESTS`; do
    if [ -e "$line" ]; then
	export BENCHFILE=`pwd`/$line
	BENCHLINE="$line "
	for rep in $REPS; do
	    echo "Starting Filename $line in subdir $rep"
	    cd $rep
	    OUT=`$MAPLE -T 3600 -w 0 -q doBench.mpl`
	    echo "$OUT"
	    CODE=$?
	    ERR=`./printError.sh`
	    TIMEOUT=`./timeOut.sh`
	    cd ..
	    if [ $CODE -eq 0 ]; then
                if [ -z "$OUT" ]; then
		    BENCHLINE="$BENCHLINE & $TIMEOUT"
		else
		    BENCHLINE="$BENCHLINE & $OUT"
		fi
	    else
		BENCHLINE="$BENCHLINE & $ERR"
            fi		
	done
	echo $BENCHLINE >> $LOG
    else
	echo "Ignoring $line"
    fi
done
